#include "nettype.h"
#include "packet.h"
#include <arpa/inet.h>
#include <time.h>

#ifndef CONN_H
#define CONN_H
class Connection {
	int                 sock;
	struct sockaddr_in  local_addr;
	struct sockaddr_in  remote_addr;
	int                 proto;
	int                 sysErr;
	int                 appErr;
	time_t              start_time;
	counter_t           bytes_transferred;
	counter_t           bytes_received;
	// Variables for determining latency
	long                transm_delay;
	time_t              last_sent;
	counter_t			n_trans;
public:
	Connection( const char* _addr, 
				port_t _port, 
				int _proto);
	Connection( int _sock, 
				const char* _addr, 
				port_t _port, 
				int _proto);
	Connection( int _sock,
				struct sockaddr_in* _addr,
				int _proto);
	const char * getAddress();
	addr_t getByteAddress();
	port_t getPort();
	int getProto();
	int sendPacket(Packet &_p);
	Packet recvPacket();
	int open();
	void closeConn();
	/* Connection statistics and information */
	bool isReady();
	int getSysErr();
	int getAppErr();
	c_id_t getId();
	long getElapsedTime();
	counter_t getBytesTransferred();
	counter_t getBytesReceived();
};
#endif
